<template>
	<view>
		<view class="msg-header">
			<view class="">消息昵称</view>
			<input class="input" v-model="msgName" type="text" placeholder="请输入昵称">
		</view>
		<j-cell-group>
			<j-cell title="用户类型" :tips="message.MsgTypeStr" :more="false"></j-cell>
			<j-cell title="用户编号" :tips="message.UserIdStr" :more="false"></j-cell>
		</j-cell-group>
		<view class="u-f-ajc bottm" @click="saveAction">保存</view>
	</view>
</template>

<script>
    const { isEmojiCharacter } = require('@/utils/util.js');
	export default {
		data() {
			return {
				msgName:'',
				message:{
					
				}
				
			}
		},
		onLoad(opt) {
			let json = decodeURIComponent(opt.message)
			this.message = JSON.parse(json)
			console.log('message==',this.message);
		},
		methods: {
			//保存
			saveAction(){
				const data = {
					deviceSn:this.message.sn,
					userType:this.message.UserType,
					userId:this.message.UserId,
					userNickname:this.msgName
				}
                if(isEmojiCharacter(this.msgName)) {
                    // 是表情包
                    uni.showToast({
                        title: '昵称不支持表情包',
                        icon: 'none'
                    })
                    return
                }
                if (this.msgName.replace(/\s/g, '') === '') {
                    uni.showToast({
                        title: '请输入昵称',
                        icon: 'none'
                    });
                    return;
                }
				getApp().globalData.api.editLockAlarmMSgName(data, (result) => {
					uni.$emit('editMsgNickname')
					uni.showToast({
						title: '保存成功',
						icon:"none",
						success: () => {
							uni.navigateBack()
						}
					});
				});
			},
			
		}
	}
</script>

<style lang="scss">
	.msg-header {
		display: flex;
		align-items: center;
		background: #fff;
		margin: 11px 11px 0 11px;
		border-radius: 5px;
		height: 120rpx;
		padding:0 20rpx;
		font-size: 28rpx;
		.input{
			margin-left: 30rpx;
			width: 70%;
		}
	}
	.bottm {
		position: fixed;
		left: 30rpx;
		right: 30rpx;
		bottom: 40rpx;
		height: 84rpx;
		background: rgba(255, 255, 255, 0.39);
		border: 1rpx solid #B9B9B9;
		border-radius: 15rpx;
		ont-size: 30rpx;
		color: #FF0025;
		font-weight: 700;
	}

</style>
